package cn.elwy.rcp.ui.composite;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

/**
 * 状态栏
 * 
 * @author HSQ
 */
public class StatusComposite extends Composite {

  private int height = 26;

  /**
   * Create the composite.
   * 
   * @param parent
   * @param style
   */
  public StatusComposite(Composite parent, int style) {
    super(parent, style);
    GridLayout gridLayout = new GridLayout(7, false);
    gridLayout.marginHeight = 2;
    setLayout(gridLayout);

    createMenu(this);

    createMsgLabel(this);

    createInfo(this);

    createProgressBar(this);

  }

  private void createMenu(Composite parent) {
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT);
    ToolItem startItem = new ToolItem(toolBar, SWT.NONE);
    startItem.setText("开始");

    ToolItem settingItem = new ToolItem(toolBar, SWT.NONE);
    settingItem.setText("设置");
  }

  private void createMsgLabel(Composite parent) {
    Label label = new Label(parent, SWT.SEPARATOR | SWT.VERTICAL);
    GridData gd_label = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_label.heightHint = height;
    label.setLayoutData(gd_label);

    CLabel msgLabel = new CLabel(parent, SWT.NONE);
    msgLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    msgLabel.setText("程序正在执行，请稍后……");
  }

  private Composite createInfo(Composite parent) {
    Label label = new Label(this, SWT.SEPARATOR | SWT.VERTICAL);
    GridData gd_label = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_label.heightHint = height;
    label.setLayoutData(gd_label);

    Composite infoComp = new Composite(this, SWT.NONE);
    infoComp.setLayout(new FormLayout());
    CLabel infoLabel = new CLabel(infoComp, SWT.NONE);
    infoLabel.setText("系统信息");
    infoLabel.setLayoutData(new FormData());
    return infoComp;
  }

  private void createProgressBar(Composite parent) {
    Label label = new Label(parent, SWT.SEPARATOR | SWT.VERTICAL);
    GridData gd_label = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_label.heightHint = height;
    label.setLayoutData(gd_label);

    Composite statusComp = new Composite(parent, SWT.NONE);
    statusComp.setLayout(new FormLayout());
    GridData gd_statusComp = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_statusComp.widthHint = 260;
    statusComp.setLayoutData(gd_statusComp);

    CLabel statusLabel = new CLabel(statusComp, SWT.NONE);
    FormData fd_statusLabel = new FormData();
    fd_statusLabel.top = new FormAttachment(0);
    fd_statusLabel.left = new FormAttachment(0, 3);
    statusLabel.setLayoutData(fd_statusLabel);
    statusLabel.setText("执行进度");

    ProgressBar progressBar = new ProgressBar(statusComp, SWT.NONE);
    FormData fd_progressBar = new FormData();
    fd_progressBar.top = new FormAttachment(statusLabel, 0, SWT.TOP);
    fd_progressBar.bottom = new FormAttachment(statusLabel, 0, SWT.BOTTOM);
    fd_progressBar.right = new FormAttachment(100);
    fd_progressBar.left = new FormAttachment(statusLabel, 10);
    progressBar.setLayoutData(fd_progressBar);
  }

  @Override
  protected void checkSubclass() {
    // Disable the check that prevents subclassing of SWT components
  }
}
